package IU;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;

import javax.print.attribute.standard.PDLOverrideSupported;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import GEF.Aplicacao;

import javax.swing.JButton;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.IOException;

import javax.swing.border.BevelBorder;
import javax.swing.JLabel;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.ImageIcon;

import mnEsq.btDiversos;
import mnEsq.btMovimentos;
import mnEsq.btOrcamento;

import java.awt.FlowLayout;

import javax.swing.BoxLayout;

import com.sun.org.apache.xerces.internal.impl.dv.dtd.NMTOKENDatatypeValidator;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.CardLayout;
import java.awt.Font;
import javax.swing.UIManager;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;

@SuppressWarnings("serial")
public class Janela extends JFrame {

	/**
	 * 
	 */
	public static String ERRORMSG;

	private JPanel contentPane;
	private Login dlgLogin;
	private Aplicacao app;
	private JPanel mnEsquerdo;
	// private JPanel mnCentro;
	private mnCentro Centro;
	private JPanel center;
	private JPanel panel;
	private JMenuBar menuBar;
	private JMenu mnFicheiro;
	private JMenuItem btSair;

	private JPanel panel_1;
	private btOrcamento mnOrcamento;
	private btDiversos mnDiversos;
	private btMovimentos mnMovimentos;
	private JPanel mnFundo;
	private JMenu mnImprimir;
	private JMenu mnFerramentas;
	private JPanel panel_2;

	/**
	 * Create the frame.
	 * 
	 * @throws IOException
	 * @throws ClassNotFoundException
	 */

	public Janela() throws ClassNotFoundException, IOException {
		setFont(new Font("Tahoma", Font.PLAIN, 12));
		setTitle("GEF - Gest\u00E3o Exclusiva de Freguesias");

		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1024, 576);
		setMinimumSize(new Dimension(854,480));
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				// TODO Auto-generated method stub
				super.windowClosing(e);
				app.desconecta();
			}
		});

		app = new Aplicacao();

		menuBar = new JMenuBar();
		menuBar.setFont(new Font("Cordia New", Font.PLAIN, 12));
		menuBar.setBorderPainted(false);
		setJMenuBar(menuBar);

		mnFicheiro = new JMenu("Ficheiro");
		mnFicheiro.setFont(new Font("Tahoma", Font.PLAIN, 12));
		menuBar.add(mnFicheiro);

		btSair = new JMenuItem("Sair");
		btSair.setFont(new Font("Tahoma", Font.PLAIN, 12));
		btSair.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				app.desconecta();
				System.exit(0);
			}
		});
		mnFicheiro.add(btSair);
		
		mnImprimir = new JMenu("Imprimir");
		mnImprimir.setFont(new Font("Tahoma", Font.PLAIN, 12));
		menuBar.add(mnImprimir);
		
		mnFerramentas = new JMenu("Ferramentas");
		mnFerramentas.setFont(new Font("Tahoma", Font.PLAIN, 12));
		menuBar.add(mnFerramentas);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		panel = new JPanel();
		contentPane.add(panel, BorderLayout.CENTER);
		panel.setLayout(new BorderLayout(0, 0));

		mnEsquerdo = new JPanel();
		mnEsquerdo.setBorder(null);
		panel.add(mnEsquerdo, BorderLayout.WEST);
		mnEsquerdo.setLayout(new BorderLayout(0, 0));

		panel_1 = new JPanel();
		panel_1.setBorder(null);
		GridBagLayout gbl_panel_1 = new GridBagLayout();
		gbl_panel_1.columnWidths = new int[] {180, 0};
		gbl_panel_1.rowHeights = new int[] {0, 0, 0, 0};
		gbl_panel_1.columnWeights = new double[]{0.0, Double.MIN_VALUE};
		gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0};
		panel_1.setLayout(gbl_panel_1);
		mnOrcamento = new btOrcamento();
		mnOrcamento.setBorder(null);
		GridBagConstraints gbc_mnOrcamento = new GridBagConstraints();
		gbc_mnOrcamento.anchor = GridBagConstraints.PAGE_START;
		gbc_mnOrcamento.fill = GridBagConstraints.BOTH;
		gbc_mnOrcamento.gridx = 0;
		gbc_mnOrcamento.gridy = 0;
		panel_1.add(mnOrcamento, gbc_mnOrcamento);
		mnOrcamento.setLayout(new BoxLayout(mnOrcamento, BoxLayout.Y_AXIS));
		
		mnDiversos = new btDiversos();
		mnDiversos.setBorder(null);
		GridBagConstraints gbc_mnDiversos = new GridBagConstraints();
		gbc_mnDiversos.anchor = GridBagConstraints.PAGE_START;
		gbc_mnDiversos.fill = GridBagConstraints.BOTH;
		gbc_mnDiversos.gridx = 0;
		gbc_mnDiversos.gridy = 1;
		panel_1.add(mnDiversos, gbc_mnDiversos);
		mnDiversos.setLayout(new BoxLayout(mnDiversos, BoxLayout.Y_AXIS));
		
		mnMovimentos = new btMovimentos();
		mnMovimentos.setBorder(null);
		GridBagConstraints gbc_mnMovimentos = new GridBagConstraints();
		gbc_mnMovimentos.anchor = GridBagConstraints.PAGE_START;
		gbc_mnMovimentos.fill = GridBagConstraints.BOTH;
		gbc_mnMovimentos.gridx = 0;
		gbc_mnMovimentos.gridy = 2;
		panel_1.add(mnMovimentos, gbc_mnMovimentos);
		mnMovimentos.setLayout(new BoxLayout(mnMovimentos, BoxLayout.Y_AXIS));
		
		mnFundo = new JPanel();
		mnFundo.setBorder(null);
		GridBagConstraints gbc_mnFundo = new GridBagConstraints();
		gbc_mnFundo.gridy = 3;
		gbc_mnFundo.gridx = 0;
		panel_1.add(mnFundo, gbc_mnFundo);
		mnFundo.setLayout(new BoxLayout(mnFundo, BoxLayout.Y_AXIS));

		
		JScrollPane listScrollPane = new JScrollPane(panel_1);
		listScrollPane.setViewportBorder(null);
        listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
        mnEsquerdo.add(listScrollPane);
        
        Centro = new mnCentro(app);
        panel.add(Centro, BorderLayout.CENTER);
//		center = new JPanel();
//		panel.add(center, BorderLayout.CENTER);
//		center.setLayout(new BorderLayout(0, 0));
//		
//		panel_2 = new JPanel();
//		JScrollPane listScrollPane2 = new JScrollPane(panel_2);
//		listScrollPane2.setViewportBorder(null);
//		center.add(listScrollPane2);
//		GridBagLayout gbl_panel_2 = new GridBagLayout();
//		gbl_panel_2.columnWidths = new int[] {10, 10, 10};
//		gbl_panel_2.rowHeights = new int[] {0};
//		gbl_panel_2.columnWeights = new double[]{0.0, 0.0, 0.0};
//		gbl_panel_2.rowWeights = new double[]{0.0};
//		panel_2.setLayout(gbl_panel_2);
//		
//		
//		
//		
//
//		
//		
//		Centro = new mnCentro(app);
//		GridBagConstraints gbc_Centro = new GridBagConstraints();
//		gbc_Centro.fill = GridBagConstraints.BOTH;
//		gbc_Centro.gridx = 1;
//		gbc_Centro.gridy = 0;
//		panel_2.add(Centro, gbc_Centro);
//		Centro.setLayout(new BoxLayout(Centro, BoxLayout.Y_AXIS));
//
		dlgLogin = new Login(app, this);
		dlgLogin.setVisible(true);
	}

	public String getERRORMSG() {
		return ERRORMSG;
	}

	public void setERRORMSG(String eRRORMSG) {
		ERRORMSG = eRRORMSG;
	}
}
